import{createRouter,createWebHashHistory, RouterView} from 'vue-router'
import { h } from 'vue'
import component from 'element-plus/es/components/tree-select/src/tree-select-option.mjs'

const router=createRouter({
    history:createWebHashHistory(),
    routes:[
      { path: '/', redirect:'/login' },
      //登录
      {
        path:'/login',
        component:()=>import('./components/login/login.vue'),
      },
      //学生端
      {
        path:'/st-home',
        component:()=>import('./components/home/home.vue'),
        redirect:'/st-home/studyPlace',
        children:[
          {
            path:'studyPlace',
            component:()=>import('./components/student/studyPlace/studyPlace.vue'),
            redirect:'/st-home/studyPlace/courses',
            children:[
              {
                path:'courses',
                component:()=>import('./components/student/studyPlace/courseList.vue')
              },
              {
                path:'work',
                component:()=>import('./components/student/studyPlace/workList.vue'),
              },
              {
                path:'workInfo',
                component:()=>import('./components/student/studyPlace/workInfo.vue')
              },
              {
                path:'workResult',
                component:()=>import('./components/student/studyPlace/workResult.vue')
              }
            ]
          },
          
        ]
      },
      //教师端
      {
        path:'/te-home',
        component:()=>import('./components/home/home.vue'),
        // redirect:'/te-home/home',
        children:[
          {
            path:'',
            component:()=>import('./components/teacher/home/home.vue'),
            // redirect:'/te-home/home/index',
            children:[
              {
                path:'',
                component:()=>import('./components/teacher/index/index.vue')
              },
              {
                path:'studentManage',
                component:()=>import('./components/teacher/student/studentList.vue')
              },
              {
                path:'courseManage',
                component:()=>import('./components/teacher/course/courseList.vue')
              },
              {
                path:'workManage',
                component:()=>import('./components/teacher/work/workList.vue'),
              },

              {
                path:'scoreManage',
                component:()=>import('./components/teacher/score/scoreList.vue')
              },
            ]
          },
          {
            path:'workScore',
            component:()=>import('./components/teacher/work/workScore.vue')
          },
          {
            path:'workInfo',
            component:()=>import('./components/teacher/work/workInfo.vue')
          },
        ]
      }
    ]
})
export default router

// router.beforeEach((to, from, next) => {
//   // 如果访问的是登录页面，直接执行下一个钩子函数
//   if(to.path === '/login'){
//     return next()
//   }
//   // 获取Token值
//   const token = localStorage.getItem('token')
//   console.log(token)
//   if (!token) {
//     // Token值不存在，强制跳转到登录页面
//     return next('/login')

//   }
//   // 存在Token值，直接执行下一个钩子函数
//   next()
// })